using UnityEngine;
using UnityEditor; 
using System.Collections;
using System.Collections.Generic;



public class CustomAnimationSampler  
{
	public static Character currentCharacter;
	public static AnimationClip currentClip;
	public static int currentFrame;
	public static Vector3 currentOffset;

	public static void CustomSampleAnimation(Character character, AnimationClip clip, int frame)
	{
        if (clip == null)
            return;

		if(currentCharacter != character)
		{
			if(currentCharacter != null)
			{
				AnimationMode.BeginSampling();
				AnimationMode.SampleAnimationClip (currentCharacter.animationRef.gameObject, currentClip, 0);
				AnimationMode.EndSampling();
				currentCharacter.animationRef.transform.localScale = Vector3.zero;
			}

			currentCharacter = character;
			currentOffset = Vector3.zero;
		}

		currentClip = clip;
		currentFrame = frame;
		AnimationMode.BeginSampling();
		AnimationMode.SampleAnimationClip (currentCharacter.animationRef.gameObject, currentClip, currentFrame/60f);
		currentCharacter.animationRef.transform.localPosition = currentOffset;
		AnimationMode.EndSampling();
	}

	public static void SampleMovement(Vector3 offset)
	{
		currentOffset = offset;
		if(currentCharacter != null)
			currentCharacter.animationRef.transform.localPosition = currentOffset;
	}
}

